#ifndef __EPOLLER_H__
#define __EPOLLER_H__

#include <vector>
#include <sys/epoll.h>
#include <unordered_map>
#include "Base/noncopyable.h"

namespace {
    const int kDefaultEvents = 16;
}

namespace tiny_muduo
{
    class Channel;

    class Epoller : public NonCopyable
    {
    public:
        typedef std::vector<epoll_event> Events;
        typedef std::vector<Channel*> Channels;

        Epoller();
        ~Epoller();

        void Remove(Channel* channel);
        void Poll(Channels& channels);
        int EpollWait() { return epoll_wait(epollfd_, &*events_.begin(), events_.size(), -1); }
        void FillActiveChannels(int eventnums, Channels& channels);
        void Update(Channel* channel);
        void UpdateChannel(int operation, Channel* channel);

    private:
        typedef std::unordered_map<int, Channel*> ChannelMap;

        int epollfd_;
        Events events_;
        ChannelMap channels_;
    };
}

#endif
